<template>
  <div>
    <a-card :bordered="false">
      <van-search placeholder="请选择条件查询" readonly @click="showSearchPopup" style="margin-top: -10px;width: 100%;padding: 0px;margin-bottom: 10px"/>

      <div class="list">
        <van-list
          v-model="loading"
          :finished="finished"
          offset="100"
          finished-text="没有更多了"
          @load="onLoadList"
          :immediate-check="false"
        >
          <div
            class="customer-list"
            v-for="(item,i) in dataSource"
            :key="i"
            >
            <div>
              <div class="name">{{ item.name }}</div>
              <div class="contact">
                <span>电话：{{ item.phone || '无' }}</span>
                <span style="margin-left: 10px;">小区：{{ item.address||'无' }}</span>
                <span style="float: right">
                  <a @click="handleInfoDetail(item.id)">查看订单</a>
                  <a-divider type="vertical" />
                  <a @click="costMaterial(item.id)">材料详情</a>
                </span>
              </div>
            </div>
          </div>
        </van-list>
      </div>
      <van-popup v-model="showSearchPopupFlag" position="top" >
        <a-card :bordered="false">
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <div>客户姓名：<a-input placeholder="请输入客户姓名" v-model="queryParam.name"></a-input></div>
            <div style="margin-top: 5px">电话：<a-input placeholder="请输入客户电话" v-model="queryParam.phone"></a-input></div>
            <div style="margin-top: 5px">项目地址：<a-input placeholder="请输入项目地址" v-model="queryParam.address"></a-input></div>
            <a-row :gutter="24" style="margin-bottom: 10px;margin-top: 10px">
              <a-col :span="12">
                <a-button type="primary" style="width: 100%" @click="searchQuery" icon="search">查询</a-button>
              </a-col>
              <a-col :span="12">
                <a-button type="primary" @click="searchReset" icon="reload" style="width: 100%">重置</a-button>
              </a-col>
            </a-row>
          </a-form>
        </a-card>
      </van-popup>
    </a-card>
    <place-order-list ref="placeOrderList"></place-order-list>
    <cost-material-list ref="costMaterialList" @ok="selectOk"></cost-material-list>
  </div>
</template>

<script>
  import '@assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { getAction,postAction } from "@api/manage";
  import placeOrderList from './modules/placeOrderList'
  import costMaterialList from './modules/costMaterialList'

  import Vue from "vue";
  export default {
    name: 'placeOrderCustomerList',
    mixins: [JeecgListMixin, mixinDevice],
    components: {
      placeOrderList,costMaterialList,
    },
    data() {
      return {
        description: '下单管理页面',
        columns:[
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            },
            fixed: 'left'
          },
          {
            title: '客户姓名',
            align: "center",
            dataIndex: 'name',
            slots: { title: 'customTitle' },
            scopedSlots: {
              customRender: 'name'
            },
          },
          {
            title: '项目地址',
            align: "center",
            dataIndex: 'address'
          },
          {
            title: '电话',
            align: "center",
            dataIndex: 'phone'
          },
          {
            title: '创建人',
            align: "center",
            dataIndex: 'createBy',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: "center",
            fixed: "right",
            width: 147,
            scopedSlots: {
              customRender: 'action'
            },
          }
        ],
        queryParam: {},
        dataSource: [],
        startDate:'',
        endDate:'',
        url: {
          list: "/ghProjectPlaceOrder/list",
          delete: "/ghCustomerInfo/delete",
        },
        selectedRowKeys: [],
        selectedRows: [],
        loading: false,
        finished: false,
        showSearchPopupFlag: false,
      }
    },
    created() {
      //this.loadData();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      showSearchPopup(){
        this.showSearchPopupFlag = true
      },
      searchQuery(){
        this.loadData(1);
        this.selectedRowKeys = []
        this.selectedRows = []
        this.showSearchPopupFlag = false
      },
      searchReset() {
        this.queryParam = {}
        this.selectedRowKeys = []
        this.selectedRows = []
        this.showSearchPopupFlag = false
        this.loadData(1);
      },
      onLoadList(e){
        this.ipagination.current++
        this.loadData(this.ipagination.current)
      },
      loadData(arg) {
        if (!this.url.list) {
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.dataSource = []
          this.finished = false;
          this.ipagination.current = 1;
        }
        let params = this.getQueryParams();//查询条件
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            //this.dataSource = res.result.records || res.result;
            this.dataSource = [...this.dataSource, ...res.result.records]
            if (res.result.total) {
              this.ipagination.total = res.result.total;
            } else {
              this.ipagination.total = 0;
            }
          } else {
            this.$message.warning(res.message)
          }
          if(res.result.records.length<10){
            this.finished = true;
          }
        }).finally(() => {
          this.loading = false
        })
      },
      //查看订单列表
      handleInfoDetail(customerId) {
        this.$refs.placeOrderList.show(customerId)
      },
      //查看材料列表
      costMaterial(customerId){
        this.$refs.costMaterialList.show(customerId);
      },
      resetSearch(){
        this.queryParam = {}
        this.loadData(1);
      },
      //加载用户列表
      loadUserListData() {
        getAction(this.url.queryUserList).then((res) => {
          if (res.success) {
            this.purchasePeopleData = res.result.records||res.result;
            this.createByData = res.result.records||res.result;
          }
        })
      },
      selectOk(){
        this.loadData(1);
      },
    }
  }
</script>
<style scoped lang="less">
  @import '~@assets/less/common.less';
  .select-pk{
    display:flex;
    align-items:center;
    margin:10px 0;
    &>span{
      font-weight: bold;
    }
    &-text{
      width: calc(100% - 6em);
      height: 30px;
      text-indent: 1em;
      line-height: 28px;
      border: 1px solid #d9d9d9;
      border-radius: 4px;
    }
  }
  .list{
    overflow-y: scroll;
    height:100vh;
  }
  ::-webkit-scrollbar {
    display: none;
  }
  .customer-list{
    /*display: flex;*/
    align-items: center;
    border-top: 1px solid #d9d9d9;
    height: 70px;
    .name{
      font-size: 13px;
      color: #161616;
      line-height: normal;
      margin-top: 10px;
    }
    .contact{
      margin-top: 5px;
      font-size: 12px;
      color: #a39f9f;
    }
  }
</style>